<%
'******************************************************************************
' Copyright (C) 2006 Google Inc.
'  
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'  
'      http://www.apache.org/licenses/LICENSE-2.0
'  
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.
'******************************************************************************
%>
<!-- #include file="../library/googleglobal.asp" -->
<%

Dim MyCart
Set MyCart = new Cart

UseCase1
' UseCase2
' UseCase3

' Print <checkout-shopping-cart> XML
' Response.Write MyCart.getXml

' Diagnose <checkout-shopping-cart> XML
' MyCart.DiagnoseXml

' Post Cart to Google Checkout 
MyCart.PostCartToGoogle

Set MyCart = Nothing


' Use Case1: US Tax rules and shipping methods
Sub UseCase1
	AddItem1
	AddItem2
	SetOptionalParameters
	AddFlatRateShippingMethod
	' AddMerchantCalculatedShippingMethod
	AddCarrierCalculatedShippingMethod
	AddDefaultTaxRule1
	AddDefaultTaxRule2
	AddAlternateTaxTable
End Sub

' Use Case2: Iternational tax rules and shipping methods
Sub UseCase2
	AddItem1
	AddItem2
	SetOptionalParameters
	AddIntlFlatRateShippingMethod
	' AddIntlMerchantCalculatedShippingMethod
	AddIntlDefaultTaxRule1
	AddIntlDefaultTaxRule2
	AddIntlAlternateTaxTable
End Sub

' Use Case3: Digital delivery
Sub UseCase3
	AddDigitalItem
	SetOptionalParameters
	AddDefaultTaxRule1
	AddDefaultTaxRule2
End Sub

' Add an item
Sub AddItem1
	Dim MyItem
	Set MyItem = New Item
	MyItem.Name = "MegaSound 2GB MP3 Player" 
	MyItem.Description = "Portable MP3 player - stores 500 songs"
	MyItem.Quantity = 1
	MyItem.UnitPrice = 178.00
	MyItem.MerchantPrivateItemData = "<color>blue</color><weight>3.2</weight>"
	MyItem.ItemWeight = 5.5
	MyCart.AddItem MyItem
	Set MyItem = Nothing
End Sub

' Add another item
Sub AddItem2
	Dim MyItem
	Set MyItem = New Item
	MyItem.Name = "Dry Food Pack AA1453" 
	MyItem.Description = "A pack of highly nutritious dried food for emergency."
	MyItem.Quantity = 1
	MyItem.UnitPrice = 35.00
	MyItem.MerchantItemId = "JMACC012"
	MyItem.TaxTableSelector = "food"
	MyItem.ItemWeight = 6.0
	MyCart.AddItem MyItem
	Set MyItem = Nothing
End Sub

' Add a digital delivery item
Sub AddDigitalItem
	Dim MyItem
	Set MyItem = New Item
	MyItem.Name = "Super Software 5000" 
	MyItem.Description = "Super Software 5000 improves download speeds."
	MyItem.Quantity = 1
	MyItem.UnitPrice = 35.00
	MyItem.DigitalContent = True
	MyItem.EmailDelivery = True
	MyItem.DigitalDescription = "Please go to &lt;a href=""http://www.example.com/download""&gt;our website&lt;/a&gt;, and enter your access key so that you can download our software."
	MyItem.Key = "1456-1514-3657-2198"
	MyItem.Url = "http://www.example.com/download"
	MyCart.AddItem MyItem
	Set MyItem = Nothing
End Sub

' Set optional parameters
Sub SetOptionalParameters
	MyCart.CartExpiration = "2007-12-31T23:59:59"
	MyCart.MerchantPrivateData = "<session-id>Session123</session-id><cart-id>Cart123</cart-id>"
	MyCart.EditCartUrl = "http://www.example.com/edit"
	MyCart.ContinueShoppingUrl = "http://www.example.com/continue"
	MyCart.RequestBuyerPhoneNumber = True
	MyCart.SetRoundingPolicy "CEILING", "TOTAL"
	MyCart.RequestInitialAuthDetails = True
	' Parameters For merchant-calculations
	' MyCart.MerchantCalculationsUrl = "https://www.example.com/callback.asp"
	' MyCart.MerchantCalculatedTax = False
	' MyCart.AcceptMerchantCoupons = True
	' MyCart.AcceptGiftCertificates = True
End Sub

' Add a flat-rate-shipping method
Sub AddFlatRateShippingMethod
	Dim MyShipping
	Set MyShipping = New FlatRateShipping
	MyShipping.Name = "UPS Ground"
	MyShipping.Price = 5.00
	MyShipping.AddShippingRestrictions CreateShippingRestrictions
	MyCart.AddShipping MyShipping
	Set MyShipping = Nothing
End Sub

' Add an international flat-rate-shipping method
Sub AddIntlFlatRateShippingMethod
	Dim MyShipping
	Set MyShipping = New FlatRateShipping
	MyShipping.Name = "FedEx 2nd Day"
	MyShipping.Price = 15.00
	MyShipping.AddShippingRestrictions CreateIntlShippingRestrictions
	MyCart.AddShipping MyShipping
	Set MyShipping = Nothing
End Sub

' Add a merchant-calculated-shipping method
Sub AddMerchantCalculatedShippingMethod
	Dim MyShipping
	Set MyShipping = New MerchantCalculatedShipping
	MyShipping.Name = "UPS Ground"
	MyShipping.Price = 5.00
	MyShipping.AddShippingRestrictions CreateShippingRestrictions
	MyShipping.AddAddressFilters CreateAddressFilters
	MyCart.AddShipping MyShipping
	Set MyShipping = Nothing
End Sub

' Add an international merchant-calculated-shipping method
Sub AddIntlMerchantCalculatedShippingMethod
	Dim MyShipping
	Set MyShipping = New MerchantCalculatedShipping
	MyShipping.Name = "FedEx 2nd Day"
	MyShipping.Price = 15.00
	MyShipping.AddShippingRestrictions CreateIntlShippingRestrictions
	MyShipping.AddAddressFilters CreateIntlAddressFilters
	MyCart.AddShipping MyShipping
	Set MyShipping = Nothing
End Sub

' Create shipping-restrictions
Function CreateShippingRestrictions
	Dim MyShippingRestrictions
	Set MyShippingRestrictions = New ShippingFilters
	MyShippingRestrictions.AllowUsPoBox = False
	MyShippingRestrictions.AddAllowedPostalArea "GB", "SW*"
	MyShippingRestrictions.AllowedCountryArea = "CONTINENTAL_48"
	MyShippingRestrictions.AllowedStates = Array("CA", "AZ", "OR", "WA")
	MyShippingRestrictions.AllowedZipPatterns = Array("9404*", "94086", "91801", "91362")
	Set CreateShippingRestrictions = MyShippingRestrictions
	Set MyShippingRestrictions = Nothing
End Function

' Create international shipping-restrictions
Function CreateIntlShippingRestrictions
	Dim MyShippingRestrictions
	Set MyShippingRestrictions = New ShippingFilters
	MyShippingRestrictions.AllowUsPoBox = False
	' MyShippingRestrictions.AllowedWorldArea = True
	MyShippingRestrictions.AddAllowedPostalArea "GB", "SW*"
	MyShippingRestrictions.AddAllowedPostalArea "DE", ""
	MyShippingRestrictions.AddAllowedPostalArea "FR", ""
	MyShippingRestrictions.AddExcludedPostalArea "US", ""
	MyShippingRestrictions.AddExcludedPostalArea "FR", ""
	Set CreateIntlShippingRestrictions = MyShippingRestrictions
	Set MyShippingRestrictions = Nothing
End Function

' Create address-filters
Function CreateAddressFilters
	Dim MyAddressFilters
	Set MyAddressFilters = New ShippingFilters
	MyAddressFilters.AllowUsPoBox = False
	MyAddressFilters.AddAllowedPostalArea "GB", "SW*"
	MyAddressFilters.AllowedCountryArea = "CONTINENTAL_48"
	MyAddressFilters.AllowedStates = Array("CA", "AZ", "OR", "WA")
	MyAddressFilters.AllowedZipPatterns = Array("9404*", "94086", "91801", "91362")
	Set CreateAddressFilters = MyAddressFilters
	Set MyAddressFilters = Nothing
End Function

' Create international address-filters
Function CreateIntlAddressFilters
	Dim MyAddressFilters
	Set MyAddressFilters = New ShippingFilters
	MyAddressFilters.AllowUsPoBox = False
	MyAddressFilters.AllowedWorldArea = True
	MyAddressFilters.AddAllowedPostalArea "GB", "SW*"
	MyAddressFilters.AddAllowedPostalArea "DE", ""
	MyAddressFilters.AddAllowedPostalArea "FR", ""
	MyAddressFilters.AddExcludedPostalArea "US", ""
	MyAddressFilters.AddExcludedPostalArea "FR", ""
	Set CreateIntlAddressFilters = MyAddressFilters
	Set MyAddressFilters = Nothing
End Function

' Add a carrier-calculated-shipping method
Sub AddCarrierCalculatedShippingMethod
	Dim MyShipping
	Set MyShipping = New CarrierCalculatedShipping

	Dim MyShippingOption
	Set MyShippingOption = New ShippingOption
	MyShippingOption.Price = 10
	MyShippingOption.ShippingCompany = "FedEx"
	MyShippingOption.CarrierPickup = "REGULAR_PICKUP"
	MyShippingOption.ShippingType = "Priority Overnight"
	MyShippingOption.AdditionalFixedCharge = "5.0"
	MyShippingOption.AdditionalVariableChargePercent = "1.10"
	MyShipping.AddShippingOption MyShippingOption
	Set MyShippingOption = Nothing

	Dim MyShippingPackage
	Set MyShippingPackage = New ShippingPackage
	MyShippingPackage.Height = 6
	MyShippingPackage.Length = 24
	MyShippingPackage.Width = 15
	MyShippingPackage.DeliveryAddressCategory = "RESIDENTIAL"

	Dim ShipFromAddress
	Set ShipFromAddress = New Address
	ShipFromAddress.ID = "ABC"
	ShipFromAddress.City = "New York"
	ShipFromAddress.Region = "NY"
	ShipFromAddress.CountryCode = "US"
	ShipFromAddress.PostalCode = "10022"
	MyShippingPackage.AddShipFrom ShipFromAddress
	Set ShipFromAddress = Nothing

	MyShipping.AddShippingPackage MyShippingPackage
	Set MyShippingPackage = Nothing

	MyCart.AddShipping MyShipping
	Set MyShipping = Nothing
End Sub

' Add <pickup> method
Sub AddPickUp
	Set MyShipping = New PickupShipping
	MyShipping.Name = "PICK-UP"
	MyShipping.Price = 0
	MyCart.AddShipping MyShipping
	Set MyShipping = Nothing
End Sub

'Add US default tax rule
Sub AddDefaultTaxRule1
	Dim MyDefaultTaxRule
	Set MyDefaultTaxRule = New DefaultTaxRule
	MyDefaultTaxRule.Rate = 0.0825
	MyDefaultTaxRule.States = Array("CA", "NY")
	MyCart.AddDefaultTaxRule MyDefaultTaxRule
	Set MyDefaultTaxRule = Nothing
End Sub

' Add US default tax rule
Sub AddDefaultTaxRule2
	Dim MyDefaultTaxRule
	Set MyDefaultTaxRule = New DefaultTaxRule
	MyDefaultTaxRule.Rate = 0.0750
	MyDefaultTaxRule.CountryArea = "ALL" 'eg: "CONTINENTAL_48", "FULL_50_STATES"
	MyCart.AddDefaultTaxRule MyDefaultTaxRule
	Set MyDefaultTaxRule = Nothing
End Sub

' Add international default tax rule
Sub AddIntlDefaultTaxRule1
	Dim MyDefaultTaxRule
	Set MyDefaultTaxRule = New DefaultTaxRule
	MyDefaultTaxRule.Rate = 0.15
	MyDefaultTaxRule.AddPostalArea "GB", ""
	MyDefaultTaxRule.AddPostalArea "FR", ""
	MyDefaultTaxRule.AddPostalArea "DE", ""
	MyCart.AddDefaultTaxRule MyDefaultTaxRule
	Set MyDefaultTaxRule = Nothing
End Sub

' Add international default tax rule
Sub AddIntlDefaultTaxRule2
	Dim MyDefaultTaxRule
	Set MyDefaultTaxRule = New DefaultTaxRule
	MyDefaultTaxRule.Rate = 0.10
	MyDefaultTaxRule.WorldArea = True
	MyCart.AddDefaultTaxRule MyDefaultTaxRule
	Set MyDefaultTaxRule = Nothing
End Sub

' Define alternate tax rules for the "food" tax table
Sub AddAlternateTaxTable
	Dim MyAlternateTaxTable, MyAlternateTaxRule
	Set MyAlternateTaxTable = New AlternateTaxTable
	MyAlternateTaxTable.Name = "food"
	MyAlternateTaxTable.Standalone = False
	' Add an alternate-tax-rule
	Set MyAlternateTaxRule = New AlternateTaxRule
	MyAlternateTaxRule.Rate = 0.05
	MyAlternateTaxRule.States = Array("CA", "NY")
	MyAlternateTaxTable.AddTaxRule MyAlternateTaxRule
	Set MyAlternateTaxRule = Nothing
	' Add another alternate-tax-rule
	Set MyAlternateTaxRule = New AlternateTaxRule
	MyAlternateTaxRule.Rate = 0.03
	MyAlternateTaxRule.CountryArea = "FULL_50_STATES"
	MyAlternateTaxTable.AddTaxRule MyAlternateTaxRule
	Set MyAlternateTaxRule = Nothing
	MyCart.AddAlternateTaxTable MyAlternateTaxTable
	Set MyAlternateTaxTable = Nothing
End Sub

' Define international alternate tax rules for the "food" tax table
Sub AddIntlAlternateTaxTable
	Dim MyAlternateTaxTable, MyAlternateTaxRule
	Set MyAlternateTaxTable = New AlternateTaxTable
	MyAlternateTaxTable.Name = "food"
	MyAlternateTaxTable.Standalone = False
	' Add an alternate-tax-rule
	Set MyAlternateTaxRule = New AlternateTaxRule
	MyAlternateTaxRule.Rate = 0.03
	MyAlternateTaxRule.AddPostalArea "GB", ""
	MyAlternateTaxRule.AddPostalArea "DE", ""
	MyAlternateTaxRule.AddPostalArea "FR", ""
	MyAlternateTaxTable.AddTaxRule MyAlternateTaxRule
	Set MyAlternateTaxRule = Nothing
	' Add another alternate-tax-rule
	Set MyAlternateTaxRule = New AlternateTaxRule
	MyAlternateTaxRule.Rate = 0.02
	MyAlternateTaxRule.AddPostalArea "GB", "SW*"
	MyAlternateTaxTable.AddTaxRule MyAlternateTaxRule
	Set MyAlternateTaxRule = Nothing
	' Add the alternate-tax-table to the cart
	MyCart.AddAlternateTaxTable MyAlternateTaxTable
	Set MyAlternateTaxTable = Nothing
End Sub

' Add parameterized-url
Sub AddParameterizedUrl
	Dim MyParameterizedUrl
	Set MyParameterizedUrl = New ParameterizedUrl
	MyParameterizedUrl.Url = "http://www.example.com/tracking?partner=12345&amp;partnerName=Bob&apos;s%20Big%20Stores"
	MyParameterizedUrl.AddUrlParameter "orderID", "order-id"
	MyParameterizedUrl.AddUrlParameter "totalCost", "order-total"
	MyParameterizedUrl.AddUrlParameter "taxes", "tax-amount"
	MyParameterizedUrl.AddUrlParameter "shipping", "shipping-amount"
	MyCart.AddParameterizedUrl MyParameterizedUrl
	Set MyParameterizedUrl = Nothing
End Sub

%>
